import api from './index'
import type { Article } from '@/models/article.model'
import { TABLE_INDEX } from './user'

// 获取所有文章
export const getAllArticles = () => {
  return api.get('/getallitems', { params: { typeIndex: TABLE_INDEX.ARTICLES } })
}

// 获取单篇文章
export const getArticle = (id: string) => {
  return api.get('/getsingle', { params: { id, typeIndex: TABLE_INDEX.ARTICLES } })
}

// 添加文章
export const addArticle = (article: Article) => {
  return api.post('/additem', { ...article, typeIndex: TABLE_INDEX.ARTICLES })
}

// 点赞文章
export const likeArticle = (id: string) => {
  return api.post('/like', { id, typeIndex: TABLE_INDEX.ARTICLES })
}

// 取消点赞
export const unlikeArticle = (id: string) => {
  return api.post('/unlike', { id, typeIndex: TABLE_INDEX.ARTICLES })
}